package com.zoagroup.funzy.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;


/**
 * The persistent class for the achievement database table.
 * 
 */
@Entity
public class Achievement implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id_achievement", unique=true, nullable=false)
	private Integer idAchievement;

	private String description;

	private String name;

	private boolean status;

	private int target;

	//bi-directional many-to-one association to TypeAchiev
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="type_achiev")
	private TypeAchiev typeAchievBean;

	//bi-directional many-to-one association to UserAchievement
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinTable(name="user_achievement"
		, joinColumns={@JoinColumn(name="id_achievement")}
		, inverseJoinColumns={@JoinColumn(name="id_user")})
	private List<User> users;

	public Achievement() {
	}

	public Integer getIdAchievement() {
		return this.idAchievement;
	}

	public void setIdAchievement(Integer idAchievement) {
		this.idAchievement = idAchievement;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean getStatus() {
		return this.status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public int getTarget() {
		return this.target;
	}

	public void setTarget(int target) {
		this.target = target;
	}

	public TypeAchiev getTypeAchievBean() {
		return this.typeAchievBean;
	}

	public void setTypeAchievBean(TypeAchiev typeAchievBean) {
		this.typeAchievBean = typeAchievBean;
	}

	public List<User> getUsers() {
		return this.users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idAchievement == null) ? 0 : idAchievement.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Achievement other = (Achievement) obj;
		if (idAchievement == null) {
			if (other.idAchievement != null)
				return false;
		} else if (!idAchievement.equals(other.idAchievement))
			return false;
		return true;
	}
}